package com.botarena.server.dao;

import java.util.Collection;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.botarena.server.model.Bot;
import com.google.appengine.api.datastore.Key;

public class BotDAO extends GenericDAO<Bot> {

	public BotDAO(PersistenceManager pm) {
		super(pm);
	}
	
	@SuppressWarnings("unchecked")
	public Collection<Bot> getRankingPart(Key contestKey, int beg, int size){
		
		Query query = pm.newQuery(getPersistentClass());
		query.setFilter("contest == chosenContest");
		query.setOrdering("rank desc");
		query.setRange(beg, beg+size);
		query.declareImports("import com.google.appengine.api.datastore.Key");
		query.declareParameters("Key chosenContest");
		
	    return (Collection<Bot>) query.execute(contestKey);
		
	}
	
	@SuppressWarnings("unchecked")
	public Collection<Bot> getRanking(Key contestKey) {
		Query query = pm.newQuery(getPersistentClass());
		query.setFilter("contest == chosenContest");
		query.setOrdering("rank desc");
		query.declareImports("import com.google.appengine.api.datastore.Key");
		query.declareParameters("Key chosenContest");
		
		return (Collection<Bot>) query.execute(contestKey);
	}

}
